package m1_simple;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Producer {
    public static void main(String[] args) throws IOException, TimeoutException {
        //连接Rabbitmq服务器
        ConnectionFactory cf = new ConnectionFactory();
        cf.setHost("192.168.126.130");
        cf.setPort(5672);//5672是通信端口
        cf.setUsername("admin");
        cf.setPassword("admin");
        Connection con = cf.newConnection();
        Channel c = con.createChannel();
        //定义队列，会通知服务器想使用一个"helloworld"队列
        //服务器会找到这个队列，如果不存在，服务器会新建队列
        c.queueDeclare("helloworld", false, false, false, null);
        //发送消息
        c.basicPublish("", "helloworld", null, "wht666".getBytes());
        System.out.println("消息已发送");
        c.close();
        con.close();
    }
}
